<template>
	<view>
		<qf-image-cropper :width="100" :height="100" :radius="200"  @crop="handleCrop"></qf-image-cropper>
	</view>
</template>

<script>
	import QfImageCropper from './qf-image-cropper/components/qf-image-cropper/qf-image-cropper.vue';
	
	import { updateHead } from '../api/index.js'
	export default {
		components: {
			QfImageCropper
		},
		methods: {
			handleCrop(e) {
				console.log(e)
				console.log(1)
				updateHead({headUrl:'data:image/jpg;base64,'+e.tempFilePath}).then(response => {
					console.log(2)
					console.log(response)
					if (response.code === 0) {
						uni.$u.toast('修改成功，需要重新登录后更新头像')
						setTimeout(function() {
							uni.redirectTo({
								url: '../index' // 跳转到头像
							});
						}, 1000);
					}else{
					 uni.$u.toast(response.msg) 
					}
					console.log(3)
				}).catch(errors => {
								// uni.$u.toast(errors)
				})
				
				// uni.previewImage({
				// 	urls: [e.tempFilePath],
				// 	current: 0
				// });
			}
 		}
	}
</script>

<style>

</style>
